// copyright 1993 Michael B. Johnson; some portions copyright 1994, MIT
// see COPYRIGHT for reuse legalities
//


#import "RIBDeclare.h"

@implementation RIBDeclare

+ initialize { return [RIBDeclare setVersion:1], self; }

- init
{
  [super init];

  name = NULL;
  declaration = NULL;
  
  return self;
}
- free
{
  if (name) { free(name); }
  if (declaration) { free(declaration); }
  return [super free];
}

- _setName:(char *)newName declaration:(char *)newDeclaration
{
  if (name)
  {  name = NXCopyStringBuffer(newName);
  }
  else
  {  name = NULL;
  }
  

  if (declaration)
  {  declaration = NXCopyStringBuffer(newDeclaration);
  }
  else
  {  declaration = NULL;
  }
  

  return self;
}

- copyFromZone:(NXZone *)zone
{
   id   newCopy = [super copyFromZone:zone];

  [newCopy _setName:name declaration:declaration];
  return newCopy;
}

- setName:(char *)newName declaration:(char *)newDeclaration
{
  if (name)
  {  free(name);
  }
  name = NXCopyStringBuffer(newName);

  if (declaration)
  {  free(declaration);
  }
  declaration = NXCopyStringBuffer(newDeclaration);

  return self;
}

- (const char *)name { return name; }
- (const char *)declaration { return declaration; }

- renderSelf:(WW3DCamera *)camera startingAt:(RtFloat)shutterOpenTime endingAt:(RtFloat)shutterCloseTime
{
  RiDeclare(name, declaration);
  return self;
}

- writeEve:(NXStream *)stream atTabLevel:(int)tab
{
   int  i;


   for (i = 0; i < tab; i++)
   {  NXPrintf(stream, "\t");
   }
   NXPrintf(stream, "Declare {%s} {%s};", name, declaration); 
   return self;
}

#define typeVector "**"
#define typeValues &name, &declaration

- read:(NXTypedStream *)stream 
{
    int version;
    [super read:stream];

    version = NXTypedStreamClassVersion(stream,"RIBDeclare");
    if (version == 0) NXReadTypes(stream, "i", &version), version=1;
    if (version == 1)
    {  NXReadTypes(stream, typeVector, typeValues);
    } 
    else 
    {
    }
    return self;
}

- write:(NXTypedStream*)stream 
{
    [super write:stream];

    NXWriteTypes(stream, typeVector, typeValues);

    return self;
}


@end
